module Bumbrella
  # A backup. Represents a description of WHAT to backup, WHERE to
  # place the backup, WHEN to perform backups and HOW to perform them.
  #
  # Note that the word 'backup' here refers to the abstract sense of a
  # backup, rather than the actual data on disk at the backup
  # destination.
  #
  # This is an abstract base class intended to be subclassed for each
  # particular type of backup (for tool X, Y, Z, etc).
  #
  # It will define the behavior required of all concrete backup
  # specifications, as well as providing the one bit of core
  # functionality that is absolutely required - the property of having
  # a name, and obtaining that name.
  class Backup
    attr_reader :name, :src, :dst

    # Initialize a backup. The name, source and destination are
    # fundamental properties of all backups and must always be given.
    def initialize(name, src, dst)
      @name = name

      @src  = src
      @dst  = dst
    end

    # Make a backup job to run this backup. Any decisions that need to
    # be taken with regards to the nature of the backup (such as based
    # on the date or time of day) is expected to be made at this
    # point.
    #
    # opts is a hash containing user supplied options to this job
    # (not formally specified at the time of this writing).
    #
    # Intended for subclasses to implement. Must return a BackupJob.
    def make_job(opts)
      raise NotImplementedError.new()
    end
  end

  class BackupJob
    def initialize(backup)
      @backup = backup
    end

    # Execute the job synchronously. If the backup fails for expected
    # reasons (i.e., external reasons rather than a bug in the code),
    # a BackupError is to be raised.
    def execute()
      raise NotImplemenetedError.new()
    end
  end
end
